#include "head_c.h"

int cd(user_t* status, const portocol_t* portocol, int socket_fd){

    // 接收flag
    int flag = 5;
    char path[1024] = {0};
    recv(socket_fd, &flag, sizeof(int), 0);
    if(flag == 1){
        // 返回根目录，不需要修改路径
        printf("目录不改动\n");
    }else if(flag == 0){
        // 接收修改的路径并拼接(复制)
        int ret = recv(socket_fd, path, sizeof(path), 0);
        if(ret == -1){
            perror("recv failed!\n");
            return -1;
        }
        strcat(status->path, path);
        if(strlen(status->path)>1){
            strcat(status->path, "/");
        }
    }else if(flag == 2){
        int ret = recv(socket_fd, path, sizeof(path), MSG_WAITALL);
        if(ret == -1){
            perror("recv failed!\n");
            return -1;
        }
        strcpy(status->path, path);
        if(strlen(status->path)>1){
            strcat(status->path, "/");
        }
    }else if(flag == 3){

        memset(status->path, 0, sizeof(status->path));
        strcat(status->path, "/");

    }else if(flag == 4){
        printf("无法进入\n");
    }
    printf("打印现在路径：%s\n", status->path);
}
